<?php
/**
 * Cube PHP Framework
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * @author Dillen / Steffen
 */

namespace Library\Mvc;

/**
 * The layout manager.
 * 
 * @class Library.Mvc.Layout
 * @extends {Library.Mvc.View}
 * @abstract
 */
class Layout extends View
{
	/**
	 * Which layout is used, the total path will
	 * be %application_path% / layouts / %layout_file%
	 * 
	 * @property String _layoutFile
	 * @var string
	 * @private
	 */
	private $_layoutFile = 'default';
    
    private $_request;
    
    public function __construct(\Library\Mvc\Request $request)
    {
        $this->_request = $request;
        
        parent::__construct();
    }
	
	/**
	 * Render the current view, the total path will
	 * be %application_path% / views / %controller% / %action% /
	 * 
	 * @method renderView
	 */
	public function renderView()
	{
		$path = $this->_request->controller . '/' . $this->_request->action . '.phtml';
		$this->render($path);
	}
	
	/**
	 * Set the current layout to another one.
	 * Default layout is: 'default'
	 * 
	 * @param String layout
	 * @method setLayout
	 */
	public function setLayout($layout)
	{
		$this->_layoutFile = $layout;
	}
	
	/**
	 * Render layout
	 * 
	 * @method renderLayout
	 */
	public function renderLayout()
	{
		$this->render($this->_layoutFile . '.phtml', array(), 'layouts');
	}
}
